package com.dxyusn.schedule.elasticjob.standalone.http;

import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
import org.apache.shardingsphere.elasticjob.http.props.HttpJobProperties;
import org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobBootstrap;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;

public class HttpJobTest
{
    public static void main(String[] args)
    {
        ScheduleJobBootstrap scheduleJobBootstrap = new ScheduleJobBootstrap(createRegistryCenter(), "HTTP",
                createJobConfiguration());
        scheduleJobBootstrap.schedule();
    }

    private static CoordinatorRegistryCenter createRegistryCenter()
    {
        CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(
                new ZookeeperConfiguration("localhost:2181", "elastic-job"));
        regCenter.init();
        return regCenter;
    }

    private static JobConfiguration createJobConfiguration()
    {
        // 创建作业配置
        JobConfiguration jobConfig =  JobConfiguration.newBuilder("javaHttpJob", 1)
                .setProperty(HttpJobProperties.URI_KEY, "http://localhost:8081/dxy/execute")
                .setProperty(HttpJobProperties.METHOD_KEY, "POST")
                .setProperty(HttpJobProperties.DATA_KEY, "source=ejob")
                .cron("0/5 * * * * ?")
                .shardingItemParameters("0=Beijing")
                .build();

        return jobConfig;

    }
}
